"use strict";
const fs = require("fs");

const Controller = require("egg").Controller;

class DeleteImgController extends Controller {
  async deleteImgArr() {
    try {
      let imgUrlObj = this.ctx.request.body;
      console.log(imgUrlObj);
      if (imgUrlObj.length == 0)
        return (this.ctx.body = {
          code: 200,
          data: { msg: "传入图片为空" }
        });
      // 循环删除商品的在文件夹图片
      imgUrlObj.forEach(item => {
        console.log(item);
        fs.unlinkSync("app" + item);
      });

      this.ctx.body = {
        code: 200,
        data: { msg: "删除成功" }
      };
    } catch (e) {
      this.ctx.body = {
        code: 500,
        data: { msg: "服务器错误" }
      };
    }
  }
}
module.exports = DeleteImgController;
